home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / modeler / parametriccurve.lwm < prev    next >
Text File  |  1993-12-13  |  5KB  |  215 lines

  1. /* CMD: Parametric Curve
  2.  * Create curve object with user-specified parametric functions
  3.  * By Arnie Cachelin © 1993 NewTek Inc.
  4.  * Tue Jun 22 01:34:00 1993
  5.  */
  6.  
  7. NUMERIC DIGITS 6
  8. call addlib "LWModelerARexx.port", 0
  9. signal on error
  10. signal on syntax
  11. call addlib "rexxsupport.library", 0, -30, 0
  12. MATHLIB="rexxmathlib.library"
  13. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  14.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  15.     call notify(1,"!Can't find "MATHLIB)
  16.     exit
  17.     END
  18.  
  19. sysnam = 'Parametric Curve'
  20. filnam = 'ENV:PCurve.state'
  21. version = 'Parametric Curve v1.0'
  22. Time=50
  23. Steps=50
  24. typ=1
  25. fil=''
  26. /* Default functions */
  27. FofT.0  = "10*cos(360*t/tmax)"
  28. FofT.1  = "10*sin(360*t/tmax)" /* 1hz sine wave */
  29. FofT.2  = "t"    /* random fluctuation 10% */
  30.  
  31. if (exists(filnam)) then do
  32.     if (~open(state, filnam, 'R')) then break
  33.     if (readln(state) ~= version) then break
  34.     parse value readln(state) with Time Steps typ .
  35.       do i=0 to 2
  36.         FofT.i = readln(state)
  37.       end i
  38.     call close state
  39. end
  40.  
  41. DO FOREVER
  42.     call req_begin sysnam
  43.     id_mes  = req_addcontrol("Make Curve using", 'T', "custom equations X(t), Y(t), Z(t)")
  44.     id_Time = req_addcontrol("Time (tmax) ", 'n',0)
  45.     id_steps  = req_addcontrol("# of steps", 'n')
  46.     id_ch.0  = req_addcontrol(" X(t) = ", 'S',40)
  47.     id_ch.1  = req_addcontrol(" Y(t) = ", 'S',40)
  48.     id_ch.2  = req_addcontrol(" Z(t) = ", 'S',40)
  49.     id_typ   = req_addcontrol("Create: ",'CH',"Curve Polygon Tube Clones")
  50.     id_act   = req_addcontrol("",'CH',"Use Load Save")
  51.     id_nam   = req_addcontrol("Parameter File: ",'T',fil)
  52.     call req_setval id_Time, Time
  53.     call req_setval id_steps, Steps
  54.     call req_setval id_typ, typ
  55.     call req_setval id_act, 1
  56.     do i=0 to 2
  57.       say i FofT.i
  58.       call req_setval id_ch.i, FofT.i
  59.       end i
  60.     if (~req_post()) then do
  61.         call req_end
  62.         exit
  63.     end
  64.     act = req_getval(id_act)
  65.     typ = req_getval(id_typ)
  66.     Time   = req_getval(id_Time) % 1
  67.     steps = req_getval(id_steps)
  68.     do i=0 to 2
  69.       FofT.i  = req_getval(id_ch.i)
  70.       end i
  71.     say act
  72.     if act=2 then do
  73.       fil=getfilename("Load File",fil)
  74.       if fil~='(none)' then do
  75.         if (~open(state, fil, 'R')) then break
  76.         parse value readln(state) with Time Steps .
  77.           do i=0 to 2
  78.             FofT.i = readln(state)
  79.           end i
  80.         call close state
  81.         call req_setval id_Time, Time
  82.         call req_setval id_steps, Steps
  83.         call req_setval id_act, 1
  84.         do i=0 to 2
  85.           say i FofT.i
  86.           call req_setval id_ch.i, FofT.i
  87.           end i
  88.         end
  89.       end     /* If act=2 */
  90.  
  91.     if act=3 then do
  92.       fil=getfilename("Save File",fil)
  93.       if fil~='(none)' then do
  94.         if (~open(state, fil, 'W')) then break
  95.         call writeln state, Time Steps
  96.           do i=0 to 2
  97.             call writeln state, FofT.i
  98.           end i
  99.         call close state
  100.         call req_setval id_act, 1
  101.         end
  102.     end
  103.  
  104.     call req_end
  105.  
  106.     if act~=1 then iterate
  107.     tmax=Time
  108.     if (open(state, filnam, 'W')) then do
  109.         call writeln state, version
  110.         call writeln state, Time Steps typ
  111.           do i=0 to 2
  112.             call writeln state, FofT.i
  113.           end i
  114.         call close state
  115.     end
  116.  
  117.     CURV=""
  118.     dt=Time/Steps
  119.     if typ=4 then do
  120.       call Center()
  121.       call cut()
  122.       end
  123.     call meter_begin Steps+2, 'Generating Curve'
  124.     call add_begin
  125.     do t=0 to Time by dt
  126.       interpret 'X='||FofT.0
  127.       interpret 'Y='||FofT.1
  128.       interpret 'Z='||FofT.2
  129.       CURV=CURV||add_point(X Y Z)||' '
  130.       call meter_step
  131.     end
  132.     /* say curv */
  133.     call Add_Curve(CURV)
  134.     call add_end
  135.     call meter_end
  136.     if typ=1 then exit
  137.     if typ=2 then do
  138.       call FreezeCurves()
  139.       exit
  140.       end
  141.     if typ=3 then do
  142.       clay=curlayer()
  143.       lay=word(emptylayers(),1)
  144.       if lay~="" then do
  145.         call setlayer(lay)
  146.         call setblayer(clay)
  147.         call req_begin "Tube Size"
  148.           SidId = req_addcontrol("Sides",'N')
  149.           RadId = req_addcontrol("Radius",'N',0)
  150.           call req_setval SidId, 8,8
  151.           call req_setval RadId, 1,1
  152.           if ~req_post() then do
  153.             call end_all()
  154.             exit
  155.             end
  156.           sides= req_getval(SidId)
  157.           r=req_getval(RadId)
  158.           call req_end()
  159.         t=0
  160.         interpret 'X0='||FofT.0
  161.         interpret 'Y0='||FofT.1
  162.         interpret 'Z0='||FofT.2
  163.         t=dt
  164.         interpret 'X1='||FofT.0
  165.         interpret 'Y1='||FofT.1
  166.         interpret 'Z1='||FofT.2
  167.         dx=X1-X0
  168.         dy=Y1-Y0
  169.         dz=Z1-Z0
  170.         if dx>dy & dx>dz then ax='X'
  171.         else if dz>dy then ax='Z'
  172.         else ax='Y'
  173.         interpret 'c='ax'0'
  174.         call makedisc(r,c,c,ax,sides,0,X0 Y0 Z0)
  175.         call railextrude(0)
  176.         end
  177.       end
  178.     if typ=4 then do
  179.       clay=curlayer()
  180.       lay=word(emptylayers(),1)
  181.       if lay~="" then do
  182.         call setlayer(lay)
  183.         call paste()
  184.         t=0
  185.         interpret 'X0='||FofT.0
  186.         interpret 'Y0='||FofT.1
  187.         interpret 'Z0='||FofT.2
  188.         call setblayer(clay)
  189.         call Move(X0 Y0 Z0)
  190.         call railclone(steps)
  191.         end
  192.       end
  193.     exit
  194.   call end_all
  195.  
  196. END /* Forever */
  197.  
  198. exit
  199.  
  200. syntax:
  201. error:
  202.   call end_all
  203.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  204.     exit
  205.  
  206. Center: Procedure
  207.   box=boundingbox()  /* Should check out empty list ...  */
  208.   parse var box n x1 x2 y1 y2 z1 z2
  209.   cx=-(x2-x1)/2
  210.   cy=-(y2-y1)/2
  211.   cz=-(z2-z1)/2
  212.   call MOVE(cx cy cz)
  213.   return box
  214.  
  215.